//
//  ZTodoNotifyCell.m
//  WeClubs
//
//  Created by Zed Link on 8/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZTodoNotifyCell.h"
#import "ZTodoConfirmButton.h"
#import "ZClientInfoCenter.h"
#import "UIView+ZUtilities.h"
#import "NSDate+ZUtilities.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@interface ZTodoNotifyCell ()

@property (weak, nonatomic) IBOutlet UIImageView *logoImgView;
@property (weak, nonatomic) IBOutlet UILabel *sponsorLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIView *separator;
@property (weak, nonatomic) IBOutlet ZTodoConfirmButton *confirmBtn;

@end

@implementation ZTodoNotifyCell

- (void)zSetupCell
{
    [super zSetupCell];
    [self setBackgroundColor:NAVBAR_BG_COLOR];
    
    // ========== 阴影与圆角处理 ==========
    [self zShadowAndCornerDeal:12];
    [self.logoImgView zCornerDeal:16];
}

- (void)updateType
{
    if (_type == ZNotifyTypeTodo) {
        [self.confirmBtn setTitle:@"确认收到" forState:UIControlStateNormal];
        [self.confirmBtn setTitle:@"已确认收到" forState:UIControlStateSelected];
    } else if (_type == ZNotifyTypeAssign) {
        
       
    }
}

#pragma mark - Control Action

- (IBAction)confirmBtnAction:(id)sender
{
    if (self.confirmBtn.selected == NO) {
        self.confirmBtn.selected = YES;
        self.confirmBtn.userInteractionEnabled = NO;
    }
}

#pragma mark - Getter & Setter

- (void)setModel:(ZTodoNotifyModel *)model
{
    _model = model;
    self.sponsorLabel.text = self.model.sponsor.sponsorName;
    self.contentLabel.text = self.model.content;
    self.dateLabel.text = [[ZClientInfoCenter sharedInstance] stringByFormatt:@"MM月dd日" fromMilliSeconds:self.model.createDate];
    
    NSString *urlStr = self.model.sponsor.sponsorAvator;
    if (urlStr != nil) {
        [self.logoImgView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    }
    
}


//优化 完美
- (void)setNoticeModel:(ZNoticeModel *)noticeModel{

    if (noticeModel== nil) return;
    
    _noticeModel = noticeModel;
    
    [self.logoImgView sd_setImageWithURL:[NSURL URLWithString:noticeModel.club_avatar] placeholderImage:defaultIcon];
    
    self.sponsorLabel.text = noticeModel.club_name;
    
    self.dateLabel.text = [[ZClientInfoCenter sharedInstance] stringByFormatt:@"MM月dd日" fromMilliSeconds:noticeModel.create_date];

    self.contentLabel.text = noticeModel.content;
    
    if (_type == ZNotifyTypeAssign) {
        NSString *normalTitle = [NSString stringWithFormat:@"再次提醒示查看成员(%zd/%zd)",_noticeModel.unread_count,_noticeModel.total_count];
        NSString *selTitle = [NSString stringWithFormat:@"所有成员都已查看该通知(%zd)",_noticeModel.already_read_count];
        [self.confirmBtn setTitle:normalTitle forState:UIControlStateNormal];
        [self.confirmBtn setTitle:selTitle forState:UIControlStateSelected];

    }
}

- (void)setType:(ZNotifyType)type
{
    _type = type;
    [self updateType];
}

@end
